<template>
	<view class="tab_bar">
		<view class="tabbarBox">
			<view class="handleBox" v-for="(item,index) in tabBarList" :key="index">
				<view class="menuBox" @click="goPages(item.pagePath)">
					<view class="menuIcon">
						<image v-if="index != selectIndex" class="img" :src="item.iconPath"></image>
						<image v-else class="img" :src="item.selectedIconPath"></image>
					</view>
					<view class="menuName">
						<text :class="index == selectIndex ? 'TextColor' : 'Text'">{{item.text}}</text>
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import home from "@/static/images/tabbar/home.png";
	import homeSelect from "@/static/images/tabbar/home_.png";
	import mine from "@/static/images/tabbar/mine.png";
	import mineSelect from "@/static/images/tabbar/mine_.png";
	export default {
		props: {
			pageIndex: {
				type: Number,
				default: 0
			}
		},
		data() {
			return {
				selectIndex: 0,
				tabBarList: [{
					pagePath: "pages/index/index",
					iconPath: home,
					selectedIconPath: homeSelect,
					text: "首页"
				}, {
					pagePath: "pages/mine/index",
					iconPath: mine,
					selectedIconPath: mineSelect,
					text: "我的"
				}],
			}

		},
		watch: {
			pageIndex: {
				handler(value) {
					this.selectIndex = value;
				},
				immediate: true,
				deep: true
			}
		},
		//uniapp子组件不支持应用生命周期，所以只能用vue生命周期
		created() {


		},
		methods: {
			//进入tabble页
			goPages(url) {
				uni.switchTab({
					url: `/${url}`
				})
			},

		},
	}
</script>
<style lang="scss">
	.tab_bar {
		// width: 100vw;
		height: 120rpx;
		position: fixed;
		bottom: 0;
		left: 0;
		right: 0;
		/* 模糊大小就是靠的blur这个函数中的数值大小 */
		// backdrop-filter: blur(10px);
		// border-radius: 60rpx;
		background-color: #fff;

		.tabbarBox {
			display: flex;
			margin-top: 10rpx;
			// padding: 0 100rpx;
			// justify-content: space-between;
			justify-content: space-evenly;


			.handleBox {
				// width: 20vw;
				height: 110rpx;


				.menuBox {
					padding: 0rpx 20rpx;
					width: 120rpx;
					height: 98%;
					text-align: center;

					.img {
						width: 50rpx;
						height: 50rpx;
					}
				}
			}
		}
	}

	.Text {
		font-size: 24rpx;
		font-family: Cochin, serif;
		font-weight: 900;
		color: #ababab;
	}

	.TextColor {
		@extend .Text;
		color: #57a9ff;
	}
</style>